﻿<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>竞价</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">						
			.fixedBox{
				border: 0px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 0px;     
				height: 0px;				
			}			


			.zixuangu{
				color: #faa1f5;
			}

			table{
			width:550px; 
			border-collapse:collapse; 
			text-align:center;
			}
			td,th{border:1px solid #696969}	
		</style>
	</head>
	<body>
	<div id="towrites" class="fixedBox" style="display:none;">
			<div class="fixedBox" style="position:relative;left:0px;width:2500px;height:100%;">	<!-- 宽度调节 -->	
				
				<div id="towrite" class="fixedBox"></div>	
			
			</div>
		</div>
		
		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script>
		<script>
			var bkcolor = $("body").css("backgroundColor")

            var isShow=true ; // 只显示昨日涨停 true ， 全部显示 false 

			var bka = "";
			var bkb = "";	
			var zxg = "";	
			var syx = "";

			var dt = "";
			var tt = "";
			var gt = "";
			var k = "0";
			var gl = "委买额";  //高亮
			var bj = [];
			var currentSortColumn = null; // 当前排序的列  
			var currentSortFlag = false; // 当前排序方向  
			window.onload = function() {

				try {
					var text1 = load("自选股.txt");  
					zxg =text1;	 
				} catch (error) {
					
				}

				try {
					var text2 = load("昨日涨停.txt");  
					syx =text2;	
				} catch (error) {
					
				}
				
				var day = new Date();
				gt = day.getTime();
				mymonth = day.getMonth()+1;
				myday = day.getDate();
				if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
				if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
				tt = day.getFullYear() + "-" + mymonth + "-" + myday;
				dt = tt;
				getSource();
				changeStyle();
				
				var iframe = document.getElementById('mapIframe');				
				iframe.src = "精选板块轮动(折线图+最高板+5).html";	
			}

			function load(name) {
				var xhr = new XMLHttpRequest()							
				okStatus = document.location.protocol === "file:" ? 0 : 200;				
				xhr.open('GET', name, false);
				xhr.overrideMimeType("text/html;charset=gb2312");//默认为utf-8				
				xhr.send(null);
				return xhr.status === okStatus ? xhr.responseText : null;
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {					
					getSource();
					changeCss(objt,"gg");					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　

	　　　$(function() {  
				var refreshTimer = setInterval(function() {  

					const dayOfWeek = (new Date()).getDay();
					var kkr=0;
					//今天是星期六或者星期日
					if (dayOfWeek === 0 || dayOfWeek === 6) {
						kkr=1;
					} 

					if (kkr===0&&time_range("9:00", "15:15")) {  
						// 保存当前状态  
						var savedSortColumn = currentSortColumn;  
						var savedSortFlag = currentSortFlag;  
						var savedTrid = trid;  
						var savedTrs = trs;  
						
						// 刷新数据  
						getSource();  
						
						// 恢复状态  
						if (savedSortColumn !== null) {  
							var table = document.getElementById("gg");  
							if (table) {  
								sortTableByColumn(table, savedSortColumn, savedSortFlag);  
								showCol(savedSortColumn, bj);  
								
								// 恢复行高亮状态  
								if(savedTrid) {  
									var tr = document.getElementById(savedTrid);  
									if(tr) tr.style.backgroundColor = "#483D8B";  
								}  
								if(savedTrs) {  
									savedTrs.split(',').forEach(function(id) {  
										var tr = document.getElementById(id);  
										if(tr) tr.style.backgroundColor = "#800080";  
									});  
								}  
							}  
						}  

						if(isShow==false){ 
							document.getElementById('showButton').textContent = '显示所有竞价异动个股';
						}
					}  
				}, 3000);  
			});
			
			Date.prototype.Format = function (fmt) {
			var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
			};			
			if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function changeStyle() {
				var div = document.getElementById("towrites");
				div.style.display= "block";
				//div.style.position= "relative"; 				
				div.style.left= "0px"; 				
				div.style.width= "1350px";
				div.style.height= "100%";
				//div.style.border= "2px solid #fff"
				
				var obj1 = document.getElementById("towrite");
				obj1.style.position= "relative";
				obj1.style.marginTop= "-10px";
 				obj1.style.float= "left";
				obj1.style.left= "0px"; 				
				obj1.style.width= "50%";	
				obj1.style.height= "100%";		
				obj1.style.fontSize= "12px";
				obj1.style.border= "0px solid #DCDCDC";
				
				var obj2 = document.getElementById("mapIframe");
				obj2.style.position= "relative"; 
				obj2.style.float= "left";
				obj2.style.marginLeft= "10px";
				//obj2.style.left= "0px"; 				
				obj2.style.width= "1200px";	
				//obj2.style.height= "100%";		
				obj2.style.fontSize= "12px";
				//obj2.style.border= "1px solid #fff";
			}
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};
			
			
			function NumberTransform(num) { 
				var result = num;
               if(Math.abs(num) > 100000000){
			    result = num / 100000000;
				result = result.toFixed(2) + "亿";
			   }else if(Math.abs(num) > 10000){
			    result = num/10000;
				result = result.toFixed(0) + "万";
			   }				   
               return result;  
			};	
			
			var xt = 1; //涨停原因相同行高亮（1:true; 0:false;）
			var trid = "";
			var trs = "";
			var objt = "";
			function changeCss(obj,id){	
				if(obj){
					trs = "";
					objt = obj;
					var t = obj.parentNode.parentNode.id;  //td父节点tr id
					var ty = t.split("#")[1];
					var ty1 = "";
					var ty2 = "";
					if(ty.indexOf("、") > -1){
						ty1 = ty.split("、")[0];
						ty2 = ty.split("、")[1];
					}
					
					var tlist = document.getElementById(id).getElementsByTagName("tr");					
					for(var i = 0; i < tlist.length; i++){
						if(tlist[i].id != ""){
							var dm = tlist[i].id.split("#")[0];
							var yy = tlist[i].id.split("#")[1];
							if(xt == 1){   //涨停原因相同行高亮
								if(t == tlist[i].id){
									tlist[i].style.backgroundColor = "#483D8B";  //选中行
									trid = t;
								}else if(ty.indexOf("、") > -1){
									if(yy.indexOf(ty1) > -1 || yy.indexOf(ty2) > -1){
										tlist[i].style.backgroundColor = "#800080"; //相同涨停原因
										trs += tlist[i].id;
									}else{
										tlist[i].style.backgroundColor = bkcolor; 				
									}	
								}else{
									if(yy.indexOf(ty) > -1){
										tlist[i].style.backgroundColor = "#800080"; //相同涨停原因
										trs += tlist[i].id;
									}else{
										tlist[i].style.backgroundColor = bkcolor; 				
									}	
								}	
							}else{
								if(t == tlist[i].id){
									tlist[i].style.backgroundColor = "#483D8B";  //选中行
									trid = t;
								}else{
									tlist[i].style.backgroundColor = bkcolor; 				
								}	
							}							
						}					
					}				
				}
			}
			
			function hover(){  //鼠标经过
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){				
					rows[i].onmouseover=function(){							
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";							
						}
					}
					rows[i].onmouseout=function(){						
						if(this.id != ""){  //过滤表头
							if(this.id == trid){  //过滤选中行
								this.style.background="#483D8B";
							}else if(trs.indexOf(this.id) > -1){
								this.style.background="#800080";
							}else{
								this.style.background=bkcolor;
							}
						}						
					}					
				}
			}			
			
			function hover1(){  //鼠标经过 相同主题高亮
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){				
					rows[i].onmouseover=function(){							
						if(this.id != ""){  //过滤表头
							//this.style.background="#800000";
							
							var ty = this.id.split("#")[1];
							var tlist = document.getElementsByTagName("tr");					
							for(var i = 0; i < tlist.length; i++){
								var dm = tlist[i].id.split("#")[0];
								var yy = tlist[i].id.split("#")[1];	
								if(trid !="" && tlist[i].id == trid){  
									tlist[i].style.background="#483D8B";
								}else if(this.id == tlist[i].id){
									tlist[i].style.backgroundColor = "#800000";  //选中行									
								}else if(ty == yy){
									tlist[i].style.backgroundColor = "#800080"; //相同涨停原因									
								}else{
									tlist[i].style.backgroundColor = bkcolor; 				
								}						
							}							
						}
					}
					
						
				}
			}			
			
			var ts = "";				
			function cDayFunc(dp) { 
				var date = dp.cal.getNewDateStr();            
				BookingRmk(date);//调用其它函数并带上参数                
			}
			
			function BookingRmk(date){         
				tt = date;
				var date1 = new Date(tt);
				var date2 = new Date(dt);							
				k = 0;
				if(date1.getTime() < date2.getTime()){			
					k = 1;
					tradeday();
				}								
				getSource();

				mapIframe.window.BookingRmk(tt);
			}

			function prev(){  //前一天
				pn = -1;
				var day = new Date(tt);	
				day.setTime(day.getTime() - 24*60*60*1000);	
				tt = day.Format("yyyy-MM-dd");
				BookingRmk(tt);
				
				mapIframe.window.BookingRmk(tt);
			}
			
			function next(){  //后一天 				
				pn = 1;
				var day = new Date(tt);	
				day.setTime(day.getTime() + 24*60*60*1000);	
				tt = day.Format("yyyy-MM-dd");
				BookingRmk(tt);			
				
				mapIframe.window.BookingRmk(tt);
			}
			
			var pn = -1;
			function tradeday() {  //判断最后交易日
				var day = new Date(tt);							
				for (i = 1; i < 100; i++){	//节假日																										
					if(i > 1){
						day.setTime(day.getTime() + pn*24*60*60*1000);							
					}	
					tt = day.Format("yyyy-MM-dd");
					//alert(tt);
					if(tt == dt){	
						k = 0;
						getSource();
						break;
					}
					var url = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=HisDaBanList&st=10&c=HisHomeDingPan&PidType=8&apiv=w26&Type=18&Is_st=1&Day=" + tt;
					var res = [];
					$.ajax({
						type: "get",
						url: url,
						dataType: "json",
						async : false,
						cache:false,
						timeout:3000,						
						success: function(data) {							
							res = data.list;							
						}
					});
					if(res.length != 0){						
						break;
					}
				}
			}	

			function toggleShowsh(){
				if(isShow==true){ 
					isShow = false;
					getSource(); 
					document.getElementById('showButton').textContent = '显示所有竞价异动个股';
					return
				}

				if(isShow==false){ 
					isShow = true;
					getSource(); 
					return
				}

			}


function getSource() {  
	 
    var div = document.getElementById('towrite');  
    div.innerHTML = '<font size="4">竞价涨停委买&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>' +   
        '<input style="width: 120px;" type="text" id="PriceDate" name="PriceDate" class="Wdate" onFocus="WdatePicker({ onpicking: cDayFunc})" />';  
    
    var back = '<a href="javascript:prev();"  style="padding-left:10px;font-size:16px;color:#fff;">←</a>';  
    var forward = '<a href="javascript:next();"  style="font-size:16px;color:#fff;">→</a>';   
	var isShowOpen ='<a href="javascript:void(0);" id="showButton" style="margin-right:30px;" onclick="toggleShowsh()">显示昨日涨停个股</a>';
    div.innerHTML += back + forward + isShowOpen + '<br><br>';  

    var allData = [];  
    
    if(k == "1") {  
        // 历史数据  
        var index = 0;  
        var hasMore = true;  
        
        while(hasMore) {  
            $.ajax({  
                type: "get",  
                url: "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=HisDaBanList&st=60&c=HisHomeDingPan&PidType=8&apiv=w26&Type=18&Is_st=1&Index=" + index + "&Day=" + tt,  
                dataType: "json",  
                async: false,  
                cache: false,  
                timeout: 3000,  
                success: function(data) {  
                    if(data && data.list && data.list.length > 0) {  
                        for (var i = 0; i < data.list.length; i++) {  
                            var row = data.list[i];  
                            allData.push({  
                                "code": row[0],  
                                "name": row[1],  
                                "zf": row[4],  
                                "wme": row[18],  
                                "je": row[20],  
                                "jjhs": row[21],  
                                "sjlt": row[15],  
                                "bk": row[11] || '-'  
                            });  
                        }  
                        index += 60;  
                    } else {  
                        hasMore = false;  
                    }  
                },  
                error: function() {  
                    hasMore = false;  
                }  
            });  
        }  
    } else {  
        // 当日数据循环加载  
        var index = 0;  
        var hasMore = true;  
        
        while(hasMore) {  
            $.ajax({  
                type: "get",  
                url: "https://apphq.longhuvip.com/w1/api/index.php?Order=1&a=MorningBiddingList&st=60&c=HomeDingPan&PhoneOSNew=1&DeviceID=ffffffff-e91e-5efd-ffff-ffffa460846b&VerSion=5.15.0.4&Token=8eda418788f6e7eeff78b6522d586afb&Index=" + index + "&PidType=0&apiv=w37&Type=4&UserID=2653861",  
                dataType: "json",  
                async: false,  
                cache: false,  
                timeout: 3000,  
                success: function(data) {  
                    if(index == 0) {  
                        tt = data.day;  
                        dt = tt;  
                    }  
                    
                    if(data.info && data.info.length > 0) {  
                        for (var i = 0; i < data.info.length; i++) {  
                            var row = data.info[i];  
                            allData.push({  
                                "code": row[0],  
                                "name": row[1],  
                                "zl": row[2],  
                                "zf": row[3],  
                                "jjzf": row[5],  
                                "wme": row[4],  
                                "jjcje": row[10],  
                                "je": row[6],  
                                "jjhs": row[7],  
                                "sjlt": row[12],  
                                "lb": row[16] || '-',  
                                "bk": row[11] || '-'  
                            });  
                        }  
                        index += 60;  
                    } else {  
                        hasMore = false;  
                    }  
                },  
                error: function() {  
                    hasMore = false;  
                }  
            });  
        }  
    }  
    
    if(allData.length > 0) {  
        writeSource(allData);  
    } else {  
        div.innerHTML += "<p style='color: red'>暂无数据</p>";  
    }  
}

function writeSource(data) {  
    if(!data || data.length === 0) return;  

    var table = document.createElement("table");  
    var thead = document.createElement("thead");  
    table.appendChild(thead);  
    var tr = document.createElement("tr");  
    thead.appendChild(tr);  

    var m = 0;  
    var v = 0;  
    bj = [];  
    
    // 创建表头  
    for(var key in data[0]) {  
        key = key.replace('code','代码')  
                 .replace('name','名称')  
                 .replace('jjzf','竞价涨幅%')  
                 .replace('zl','价格')  
                 .replace('wme','委买额')  
                 .replace('lb','连板')  
                 .replace('bk','板块')  
                 .replace('zf','实时涨幅%')  
                 .replace('jjcje','竞价成交额')  
                 .replace('je','净额')  
                 .replace('jjhs','竞价换手%')  
                 .replace('sjlt','实际流通');  
                 
        var th = document.createElement("th");  
        th.innerHTML = key;  
        tr.appendChild(th);  
        
        if(gl == key.replace("%","")) {  
            v = m;  
            th.style.color = "#FF6633";  
        }  
        if(key == "主力" || key == "连板" || key == "板块") {  
            bj.push(m);  
            th.style.color = "#FFA500";  
        }  


        m++;  
    }  

    var tbody = document.createElement("tbody");  
    table.appendChild(tbody);  

    // 填充数据  
    for(var i = 0; i < data.length; i++) {  
        var tr = document.createElement("tr");  
        var p = 1;  
        var dm = "";  

		var lb=data[i]["lb"] 

		if (lb=="首板" || lb=="-"){
			if (isShow==false){
				continue
			} 
		}
        
        for(var key in data[i]) {  
            var td = document.createElement("td");  
            var rc = data[i][key];  
            
            if(p == 1) {  
                dm = rc;  
            } else if(key == 'zf' || key == 'jjzf' || key == 'jjhs') {  
                rc = keepTwoDecimal(rc);  
            } else if(key == 'wme' || key == 'je' || key == 'jjcje' || key == 'sjlt') {  
                rc = NumberTransform(rc);  
            }  

            td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeCss(this,\"gg\")'>" + rc + "</a>";  
            
            if(p == v + 1) {  
                if(parseFloat(rc) >= 0) {  
                    td.getElementsByTagName("a")[0].style.color = "#FF6633";  
                } else {  
                    td.getElementsByTagName("a")[0].style.color = "#00FF00";  
                }  
            }  
            if(bj.indexOf(p - 1) > -1) {  
                td.getElementsByTagName("a")[0].style.color = "#FFA500";  
            }  
 
			if(zxg.indexOf(dm) > -1){
				td.getElementsByTagName("a")[0].style.color = "#faa1f5";  
			}
				
            tr.appendChild(td);  
            p++;  
        }   
        
        tr.id = dm + "#" + (data[i]['bk'] || '');  
        tbody.appendChild(tr);  
    }  

   var div = document.getElementById("towrite");  
    div.appendChild(table);  
    table.id = "gg";  
    
    makeSortable(table);  
    
    // 恢复排序状态  
    if (currentSortColumn !== null) {  
        setTimeout(function() {  
            sortTableByColumn(table, currentSortColumn, currentSortFlag);  
            showCol(currentSortColumn, bj);  
        }, 0);  
    }  
    
    document.getElementById("PriceDate").value = tt;  
    hover();  
}  
			
			//隐藏某列				
            function changeTable(table,ss) {	
				var trs = table.rows;
				ss = ss + '#';
				var aa = ss.split('#');
				for (var j = 0; j < aa.length; j++) {
					if(aa[j] != ""){
						for (var i = 0, len = trs.length; i < len; i++) {					
							var p = aa[j];
							var cell = trs[i].cells[p]; 
							cell.style.display = 'none';
						}
					}
				}					
			}
			
			function makeSortable(table) {  
    var headers = table.getElementsByTagName("th");  
    for(var i = 0; i < headers.length; i++) {  
        headers[i].onclick = function(columnIndex) {  
            return function() {  
                // 更新排序状态  
                if(currentSortColumn === columnIndex) {  
                    currentSortFlag = !currentSortFlag;  
                } else {  
                    currentSortColumn = columnIndex;  
                    currentSortFlag = false;  
                }  
                
                // 应用排序  
                sortTableByColumn(table, columnIndex, currentSortFlag);  
                showCol(columnIndex, bj);  
            };  
        }(i);  
    }  
}function sortTableByColumn(table, column, flag) {  
    var tbody = table.tBodies[0];  
    var rows = Array.from(tbody.getElementsByTagName("tr"));  
    var headers = table.getElementsByTagName("th");  
    var headtxt = headers[column].textContent;  

    rows.sort(function(row1, row2) {  
        var cell1 = row1.getElementsByTagName("td")[column];  
        var cell2 = row2.getElementsByTagName("td")[column];  
        var val1 = cell1.textContent || cell1.innerText;  
        var val2 = cell2.textContent || cell2.innerText;  

        if (headtxt.indexOf("名称") !== -1 ||   
            headtxt.indexOf("主力") !== -1 ||   
            headtxt.indexOf("连板") !== -1 ||   
            headtxt.indexOf("主题") !== -1 ||  
            headtxt.indexOf("板块") !== -1) {  
            return flag ? val2.localeCompare(val1) : val1.localeCompare(val2);  
        }  

        val1 = parseNumericValue(val1);  
        val2 = parseNumericValue(val2);  
        return flag ? val2 - val1 : val1 - val2;  
    });  

    while (tbody.firstChild) {  
        tbody.removeChild(tbody.firstChild);  
    }  
    rows.forEach(row => tbody.appendChild(row));  
}

// 辅助函数：解析数值  
function parseNumericValue(val) {  
    if (val === "-") return 0;  
    val = val.replace(" ", "0").replace("无", "1000").replace("NaN", "0");  
    if (val.indexOf("万") !== -1) {  
        return parseFloat(val) * 10000;  
    } else if (val.indexOf("亿") !== -1) {  
        return parseFloat(val) * 100000000;  
    }  
    return parseFloat(val) || 0;  
}
			function showCol(iCol,arr){	 //(选中列，标记列)	
				var oTable = document.getElementsByTagName('table')[0];						
				//表头
				var th = oTable.getElementsByTagName("th");						
				for (var i=0;i < th.length; i++){	    //列遍历
					th[i].style.color = "#E5E5E5";      //还原					
					if(arr.length > 0 && arr.indexOf(i) > -1){  //BJ列高亮
						th[i].style.color = "#FFA500";
					}
					th[iCol].style.color = "#FFFF80";	//选中				
				}
				
				var tr = oTable.getElementsByTagName("tr");	
				for (var i=1;i < tr.length; i++){	//行遍历
					var otagsA = tr[i].getElementsByTagName("a");
					for (var j=0;j < otagsA.length; j++){	//列遍历
						otagsA[j].style.color = "#E5E5E5";	//还原																
						if(arr.length > 0 && arr.indexOf(j) > -1){  //BJ列高亮
							otagsA[j].style.color = "#FFA500";
						}
					}
					var value = otagsA[iCol].innerText.replace(/(万)|(亿)/g,'');
					if(!isNaN(parseFloat(value)) && isFinite(value)){  //判断列是否为数字
						if(parseFloat(value) >= 0){
							otagsA[iCol].style.color = "#FF6633";     //正负颜色
						}else{
							otagsA[iCol].style.color = "#00FF00";
						}
					}else{
						otagsA[iCol].style.color = "#FF6633";
					}					
				}					
			}	
			
		</script>	
	</body>
</html>